package com.xb.loan.usercenter.user.sms.service.impl;

import com.xb.loan.log.exception.BizException;
import com.xb.loan.usercenter.service.dict.IDistrictService;
import com.xb.loan.usercenter.service.sms.IPhoneAreaService;
import com.xb.loan.usercenter.service.sms.bean.PhoneAreaVO;
import com.xb.loan.usercenter.service.sms.exception.IPhoneAreaServiceException;
import com.xb.loan.usercenter.user.sms.dao.PhoneAreaDao;
import com.xb.loan.usercenter.user.sms.dao.bean.PhoneArea;
import com.xb.loan.util.common.ObjectOperation;
import com.xb.loan.util.log.DefaultLoggerFacotry;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 手机所属地区处理
 */
@Service("phoneAreaService")
public class PhoneAreaServiceImpl implements IPhoneAreaService {

	private static Logger logger = DefaultLoggerFacotry.getLogger(PhoneAreaServiceImpl.class);
	
	@Autowired
    private IDistrictService districtService;
	
	@Autowired
    private PhoneAreaDao phoneAreaDao;
	
    @Override
    public PhoneAreaVO queryPhoneArea(String phone) throws BizException {
        
        PhoneArea phoneArea = phoneAreaDao.queryPhoneArea(phone.substring(0,7));
        
        if(null == phoneArea){
            
             throw IPhoneAreaServiceException.PhoneAreaNotExist;
        }else{
        	
        	if(phoneArea.getProvinceCode() == null || "".equals(phoneArea.getProvinceCode())){
           	 
           	 	throw IPhoneAreaServiceException.ProvinceCodeNoExist;
            }
            return ObjectOperation.convertByClasses(phoneArea, PhoneAreaVO.class);
        }
    }

    
}
